#include <string>
#include <vector>
#include <iostream>
#include <thread>
#include "coroutine.hpp"

void run_in_coroutine2() {
    LOG_CO("run_in_coroutine2 begin");
    LOG_CO("run_in_coroutine2 end");
}

void run_in_coroutine() {
    LOG_CO("run_in_coroutine begin");

    LOG_CO("before run_in_coroutine yield");
    jizhe::Coroutine::GetThis()->yield();
    LOG_CO("after run_in_coroutine yield");

    LOG_CO("run_in_coroutine end");
    // coroutine结束之后会自动返回主协程运行
}

void test_coroutine2() {
    jizhe::Coroutine::GetThis();
    jizhe::Coroutine::ptr coroutine(new jizhe::Coroutine(run_in_coroutine, 0));
    LOG_CO("before test_coroutine resume");
    coroutine->resume();
    LOG_CO("after test_coroutine resume");
    LOG_CO("before test_coroutine resume again");
    coroutine->resume();
    LOG_CO("after test_coroutine resume again");
}

int main(int argc, char *argv[]) {

    LOG_CO("main begin");

    test_coroutine2();
    // std::vector<std::jthread*> pools;

    // for(int i=0; i<5; ++i) {
    //     pools.emplace_back(new std::jthread(test_coroutine));
    // }

    LOG_CO("main end");
    return 0;
}